/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.panomedic.colors;

import com.panomedic.utils.Utils;

/**
 *
 * @author Yare
 */
public class YxyPixel extends Pixel {
    
    public YxyPixel(){
        super();
    }
    
    /*  Constructor from int[4] RGBA pixel   */
    public YxyPixel(int[] rgba) {
        super();
        if (rgba == null || rgba.length < 4 )
            return;
        comp = ColorConvertor.RGBtoYxy(rgba);
        if ( rgba[3] == 255 )
            opaque = true;
        else opaque = false;
    }

    public int[] getRGBA() {
        int[] px = new int[4];
        int[] px2 = null;
        px2 = ColorConvertor.YxytoRGB(comp);
        if (px2 != null) {
            px2 = Utils.cutPixelOverlap(px2);
            System.arraycopy(px2, 0, px, 0, 3);
        }
        if ( opaque )
            px[3] = 255;
        else px[3] = 0;
        
        return px;
    }

    @Override
    public String getName() {
        return "Yxy";
    }
    
    public void setComp(int[] rgba){
        comp = ColorConvertor.RGBtoYxy(rgba);
    }
    
  
    
    public static void main(String[] args){
        int[] test = new int[]{170,200,100,255};
        YxyPixel  pix = new YxyPixel(test);
        System.out.println("Result: " + pix.getComp()[0]+"  "+pix.getComp()[1]+"  "+pix.getComp()[2]+", opaque: "+pix.isOpaque());
        test = pix.getRGBA();
        System.out.println("Result: " + test[0]+"  "+test[1]+"  "+test[2]+", alpha="+test[3]);
        
    }


    
    
    
    

}
